package com.ksp.wke.kspu05;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ksp.api.KSPAPI_UsrAuth;
import com.ksp.dom.KSPDOM_ResDta;

import net.minidev.json.JSONArray;

@Controller
public class KSPU05Controller {

	@Autowired
	private KSPU05Mapper kspu05Mapper;

	@RequestMapping("/usr/KSPU05")
	@ResponseBody
	public KSPDOM_ResDta iniPam(ServletRequest request) {
		HttpServletRequest hreq = (HttpServletRequest)request;
		String wCooTkn = hreq.getParameter("COO_TKN");
		
		if (!KSPAPI_UsrAuth.checkUsr(request, wCooTkn)) {
			return KSPDOM_ResDta.buildFail("登录用户异常");
		}
		
		Map<String, Object> wPamMap = new HashMap<>();
		KSPDOM_ResDta wResDta = new KSPDOM_ResDta();
		try {
			wResDta = exeSrv(wPamMap);
		} catch (Exception e) {
			wResDta.setCod("400");
			wResDta.setMsg(e.getMessage());
		}
		
		return wResDta;
	}

	public KSPDOM_ResDta exeSrv(Map<String, Object> pPamMap) {
		List<Map<String, Object>> wQryPwdLst = kspu05Mapper.qryUsrLst(pPamMap);
		return KSPDOM_ResDta.buildSucc(JSONArray.toJSONString(wQryPwdLst));
	}
}
